<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * 购物车接口 测试类
 */
namespace app\test\controller;

use app\utils\BoyeService;
use app\test\controller\Ava;

class ShoppingCart extends Ava{
	//购物车添加
	public function add(){
		if(IS_AJAX){

			$data = [
				'uid'         => I('post.uid',''),
				'pid'         => I('post.pid',''),
				'count'       => I('post.count',''),
				'psku_id'     => I('post.psku_id',''),
				'group_id'    => I('post.group_id',''),
				'package_id'  => I('post.package_id',''),
				'api_ver'     => $this->api_ver,
				'notify_id'   => $this->notify_id,
				'alg'         => $this->alg,
				'type'        => 'BY_ShoppingCart_add',
			];
			$service = new BoyeService();
			$result = $service->callRemote("",$data,true);
			echo $this->parseResult($result);

		}else{
			$this->assign('type','BY_ShoppingCart_add');
			$this->assign('field',[
				['api_ver',101,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['pid','1,2',LL('need-mark product IDs')],
				['count','1,1',LL('need-mark product counts')],
				['psku_id','1281,1204',LL('need-mark product sku IDs')],
				['group_id','',LL('prodcut-group ID')],
				['package_id','1',LL('product-package ID')],
			]);
			echo $this->display('ava/test');
		}
	}

	//购物车修改
	public function edit(){
		if(IS_AJAX){
			$data = [
				'uid'				=>I('post.uid',0),
				'id'				=>I('post.id',0),
				'count'			=>I('post.count',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_edit',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_edit');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',42,LL('need-mark user ID')],
				['id',493,LL('need-mark order-cart-ids')],
				['count',2,LL('need-mark count')],
			]);
			echo $this->display('ava/test');
		}
	}
	//购物车删除
	public function delete(){
		if(IS_AJAX){
			$data = [
				'uid'				=>I('post.uid',0),
				'id'				=>I('post.id',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_delete',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_delete');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['id',823,LL('need-mark order-cart-ids')],
				['uid',143,LL('need-mark user ID')],
			]);
			echo $this->display('ava/test');
		}
	}
	//查看库存
	public function count(){
		if(IS_AJAX){
			$data = [
				'psku_id'		=>I('post.psku_id',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_count',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_count');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['psku_id',95,LL('need-mark product sku ID')],
			]);
			echo $this->display('ava/test');
		}
	}
	//查看购物车
	public function getInfo(){
		if(IS_AJAX){
			$data = [
				'id'		    =>I('post.id',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_getInfo',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_getInfo');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['id',494,LL('need-mark shopping-cart ID')],
			]);
			echo $this->display('ava/test');
		}
	}
	//分页查看购物车 - 废弃
	public function query(){
		if(IS_AJAX){
			$data = [
				'uid'       =>I('post.uid',0),
				'page_no'   =>I('post.page_no',0),
				'page_size' =>I('post.page_size',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_query',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_query');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
				['page_no',1,L('page')],
				['page_size',10,LL('page size')],
			]);
			echo $this->display('ava/test');
		}
	}
	//全部购物车
	public function all(){
		if(IS_AJAX){
			$data = [
				'uid'       =>I('post.uid',0),
				'api_ver'   =>$this->api_ver,
				'notify_id' =>$this->notify_id,
				'alg'       =>$this->alg,
				'type'      =>'BY_ShoppingCart_all',
			];
			$service = new BoyeService();
			$result = $service -> callRemote("",$data,true);
			echo $this->parseResult($result);
		}else{
			$this->assign('type','BY_ShoppingCart_all');
			$this->assign('field',[
				['api_ver',$this->api_ver,LL('need-mark api version')],
				['uid',143,LL('need-mark user ID')],
			]);
			echo $this->display('ava/test');
		}
	}
}